package com.hzjy.manage.controller;

import java.util.Date;
import java.util.List;

import com.hzjy.api.beans.HzjyHotOriginators;
import com.hzjy.api.service.impl.HzjyHotPeopleServiceImpl;
import com.hzjy.api.vo.HzjyHotPeople;
import com.hzjy.manage.service.impl.HzjyUserServiceImpl;
import com.hzjy.manage.vo.HzjyUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hzjy.common.annotation.Log;
import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.enums.BusinessType;
import com.hzjy.common.core.page.TableDataInfo;

/**
 * 热门权益人榜单(每天0点更新榜单)Controller
 * 
 * @author hzjy
 * @date 2020-08-29
 */
@RestController
@RequestMapping("/manage/originators")
public class HotOriginatorsController extends BaseController
{
    @Autowired
    private HzjyHotPeopleServiceImpl hzjyHotPeopleService;

    @Autowired
    private HzjyUserServiceImpl hzjyUserService;

    /**
     * 查询热门权益人榜单(每天0点更新榜单)列表
     */
    @PreAuthorize("@ss.hasPermi('manage:originators:list')")
    @GetMapping("/list")
    public TableDataInfo list(HzjyHotPeople hzjyHotPeople)
    {
        startPage();
        List<HzjyHotPeople> list = hzjyHotPeopleService.selectHzjyHotPeopleList(hzjyHotPeople);
        return getDataTable(list);
    }

    /**
     * 导出热门权益人榜单(每天0点更新榜单)列表
     */
    /*@PreAuthorize("@ss.hasPermi('system:originators:export')")
    @Log(title = "热门权益人榜单(每天0点更新榜单)", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HzjyHotOriginators hzjyHotOriginators)
    {
        List<HzjyHotOriginators> list = hotOriginatorsService.selectHzjyHotOriginatorsList(hzjyHotOriginators);
        ExcelUtil<HzjyHotOriginators> util = new ExcelUtil<HzjyHotOriginators>(HzjyHotOriginators.class);
        return util.exportExcel(list, "originators");
    }*/

    /**
     * 获取热门权益人榜单(每天0点更新榜单)详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:originators:query')")
    @GetMapping("/selectOne")
    public AjaxResult getInfo( Long id)
    {
        return AjaxResult.success(hzjyHotPeopleService.selectHzjyHotPeopleById(id));
    }

    /**
     * 新增热门权益人榜单(每天0点更新榜单)
     */
    @PreAuthorize("@ss.hasPermi('manage:originators:add')")
    @Log(title = "热门权益人榜单(每天0点更新榜单)", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody HzjyHotPeople hzjyHotPeople)
    {
        hzjyHotPeople.setCreateTime(new Date());
        return toAjax(hzjyHotPeopleService.insertHzjyHotPeople(hzjyHotPeople));
    }

    /**
     * 修改热门权益人榜单(每天0点更新榜单)
     */
    @PreAuthorize("@ss.hasPermi('manage:originators:edit')")
    @Log(title = "热门权益人榜单(每天0点更新榜单)", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody HzjyHotPeople hzjyHotPeople)
    {
        hzjyHotPeople.setUpdateTime(new Date());
        return toAjax(hzjyHotPeopleService.updateHzjyHotPeople(hzjyHotPeople));
    }

    /**
     * 删除热门权益人榜单(每天0点更新榜单)
     */
    @PreAuthorize("@ss.hasPermi('manage:originators:remove')")
    @Log(title = "热门权益人榜单(每天0点更新榜单)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hzjyHotPeopleService.deleteHzjyHotPeopleByIds(ids));
    }

    /**
     * 删除单条热门权益人榜单(每天0点更新榜单)
     */
    @PreAuthorize("@ss.hasPermi('manage:originators:delete')")
    @Log(title = "热门权益人榜单(每天0点更新榜单)", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody HzjyHotPeople hzjyHotPeople)
    {
        return toAjax(hzjyHotPeopleService.deleteHzjyHotPeopleById(hzjyHotPeople.getId()));
    }

    /**
     * 查询用户下拉列表
     * @return
     */
    @PreAuthorize("@ss.hasPermi('manage:originators:selectUserList')")
    @GetMapping("/selectUserList")
    public AjaxResult selectUserList(HzjyUser hzjyUser){
        List<HzjyUser> hzjyUsers = hzjyUserService.selectHzjyUserList(hzjyUser);
        return AjaxResult.success(hzjyUsers);
    }
}
